// Copyright 2023 Srhino Co., Ltd. All rights reserved.

package main

import (
	"context"
	ifacev2 "git.ouryun.cn/lzj1/grpc-bidirectional-stream/pkg/interfaces/v2"
	"git.ouryun.cn/lzj1/grpc-bidirectional-stream/pkg/services/v2"
	"google.golang.org/grpc/metadata"
	webserver2 "ouryun.com/web-demov2/client2/pkg/webserver"
	"ouryun.com/web-demov2/utils"
)

func main() {
	var server ifacev2.GrpcServer
	app := webserver2.NewServer("127.0.0.1", 9081, server)
	wait := make(chan struct{})
	md := metadata.Pairs("client-id", v2.SERVER_TYPE_SC)
	ctx := metadata.NewOutgoingContext(context.Background(), md)
	server = v2.NewGrpcClient("127.0.0.1:10086", v2.SERVER_TYPE_SC, ctx, app.Callback)
	app.SetGs(server)
	go func() {
		err := server.Start()
		if err != nil {
			utils.Logger.Error(err)
		}
	}()
	// 启动web服务

	err := app.Start()
	if err != nil {
		utils.Logger.Error(err)
	}

	<-wait
}

//func Callback(message *apis.StreamMessage) {
//	request, err := server.Request(message, nil, apis.StreamMessage_RESPONSE_TYPE)
//	if err != nil {
//		return
//	}
//	utils.Logger.Infof("收到响应消息3%v", request)
//}
